import React, {PureComponent} from 'react';
import {EditableTreeTable, TreeTable} from 'jh-lib';
import {Button, Card} from "antd";
import ComponentType from "../../Config/ComponentType";
import '../../../global.less'

const x = 3;
const y = 2;
const z = 1;
const gData = [];

const generateData = (_level, _preKey, _tns) => {
    const preKey = _preKey || '0';
    const tns = _tns || gData;

    const children = [];
    for (let i = 0; i < x; i++) {
        const code = `${preKey}-${i}`;
        tns.push({title: code, key: code, name: code, code: code});
        if (i < y) {
            children.push(code);
        }
    }
    if (_level < 0) {
        return tns;
    }
    const level = _level - 1;
    children.forEach((code, index) => {
        tns[index].children = [];
        return generateData(level, code, tns[index].children);
    });
};
generateData(z);

const cols = [
    {
        remark: '应用',
        name: 'app',
        floatNum: '',
        sum: false,
        reg: '',
        expression: '',
        format: '',
        align: '',
        colWidth: 100,
        componentType: ComponentType.FINDER,
        finderCode: 'USER',
        appCode: 'USER'
    },
    {
        remark: '顺序',
        name: 'sort',
        floatNum: '0',
        sum: false,
        reg: '',
        expression: '',
        format: '',
        align: '',
        colWidth: 100,
        componentType: ComponentType.NUMBER_INPUT,
    }
]

export default class BaseTest extends PureComponent {

    compRef;


    setFieldInsByName(fieldName, ins, customprops) {
        this.compRef = ins;
    }

    render() {
        return (
            <>
                <Card title={'EditableTreeTable'}
                      bodyStyle={{padding: 0}}
                      extra={[
                          <Button key={'setData'} onClick={() => {
                              this.compRef.setData(gData);
                          }}>setData</Button>,
                          <Button key={'getAjaxData'} onClick={() => {
                              console.log('getAjaxData >>>', this.compRef.getAjaxData());
                          }}>getAjaxData</Button>,
                      ]}
                >
                    <TreeTable
                        leftList={gData}
                        rightList={[]}
                        colsConf={cols}
                    />
                </Card>
            </>
        )
    }
}